package com.ehi.tsconfig.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.util.List;


@Service
public class TsconfigService {
    private final Logger logger = LoggerFactory.getLogger(TsconfigService.class);

    public void createConfigFile(File output, String configJson) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            Object obj = mapper.readValue(configJson, Object.class);
            mapper.writerWithDefaultPrettyPrinter().writeValue(output, obj);
        } catch (IOException e) {
            logger.error("write to config json file error", e);
        }
    }

    public ExecuteResult cloneProject() {
        GitHandler handler = new GitHandler();
        return handler.createProject(null);
    }

    public List<ExecuteResult> newInstance() {
        GitHandler handler = new GitHandler();
        return handler.createNewInstance(null);
    }
}
